package com.zhengyisky.controller;

import com.zhengyisky.service.DataExportService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class ExportController {

    @Autowired
    private DataExportService exportService;

    @GetMapping("/export")
    public ResponseEntity<String> triggerExport() {
        new Thread(() -> {
            long t1 = System.currentTimeMillis();
            try {
                exportService.exportLargeData("/Users/apple/", 20000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            long t2 = System.currentTimeMillis();
            System.out.println(t2-t1);
        }).start();
        return ResponseEntity.ok("导出任务已启动");
    }
}
